package ex_inheritance;

import ex_class.Car;

public class ObjectCastingExam {
	public static void testCar(Car car) {
		car.run();
		car.stop();
		if (car instanceof Truck) {
			Truck truck = (Truck) car;
			truck.convey();
		}
	}
	
	public static void main(String[] args) {
		Car myTruck = new Truck("봉고", "파랑", true, 1500);
		
		//Truck anyTruck = myTruck;
		Truck anyTruck = (Truck) myTruck;
		anyTruck.convey();
		
//		Car pride = new Car("프라이드", "빨강", true);
//		anyTruck = (Truck) pride;
//		anyTruck.convey();
		
		System.out.println("----------------------------");
		
		Car[] cars = {
			new Car("그랜저", "검정", true),
			new Truck("포터", "파랑", false, 1500),
			new Car("소나타", "흰색",  true)
		};
		
		for (Car car : cars) {
			testCar(car);
		}
	}
}
